<!doctype html>
<html
    version="HTML+RDFa 1.0"
    xmlns:sioc="http://rdfs.org/sioc/ns#" 
    xmlns:dcterms="http://purl.org/dc/terms/">
    <head>
        <title>VIE example</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <script>
            GENTICS_Aloha_base = 'http://aloha-editor.org/aloha-0.9.3/aloha/';

            jQuery(document).ready(function() {

                // Implement our own Backbone.sync method
                Backbone.sync = function(method, model, options) {
                    console.log(method, model.toJSON());
                };

                // Load collections from page so they can be managed
                VIE.CollectionManager.loadCollections();

                // Functionality for adding items
                jQuery('#addbutton').bind('click', function() {
                    VIE.CollectionManager.collections[0].add([{}]);
                });

                // Make all RDFa entities editable
                jQuery('[typeof][about]').each(function() {
                    jQuery(this).vieSemanticAloha();
                });

                jQuery('#savebutton').bind('click', function() {
                    // Go through all Backbone model instances loaded for the page
                    jQuery.each(VIE.ContainerManager.instances, function(index, objectInstance) {
                        if (!VIE.AlohaEditable.refreshFromEditables(objectInstance)) {
                            // No changes to this object, skip
                            return true;
                        }               

                        // Set the modified properties to the model instance
                        objectInstance.save(null, {
                            success: function(savedModel, response) {
                                alert(savedModel.id + " was saved, see JS console for details");
                                jQuery.each(modifiedProperties, function(propertyName, propertyValue) {
                                    savedModel.editables[propertyName].setUnmodified();
                                });
                            },
                            error: function(response) {
                                console.log("Save failed");
                            }
                        });
                    });
                });

                jQuery('#tweakbutton').bind('click', function() {
                    VIE.ContainerManager.instances[0].set({'dcterms:title': 'Hello, world!'});
                });
            });
        </script>
        <script src="http://aloha-editor.org/aloha-0.9.3/aloha/aloha.js"></script>
        <script src="http://aloha-editor.org/aloha-0.9.3/aloha/plugins/com.gentics.aloha.plugins.Format/plugin.js"></script>
        <script src="http://aloha-editor.org/aloha-0.9.3/aloha/plugins/com.gentics.aloha.plugins.HighlightEditables/plugin.js"></script>
        <script src="underscore-min.js"></script>
        <script src="backbone-min.js"></script>
        <script src="vie-containermanager.js"></script>
        <script src="vie-collectionmanager.js"></script>
        <script src="vie-aloha.js"></script>
    </head>
    <body>
        <p>Click on the content below to edit it, then <button id="savebutton">Save</button>, <button id="addbutton">Add items</button> or <button id="tweakbutton">Change via JS</button>.</p>

        <div typeof="http://purl.org/dc/dcmitype/Collection" rel="dcterms:hasPart">
            <article typeof="sioc:Post" about="http://example.net/blog/news_item">
                <h1 property="dcterms:title">News item title</h1>
                <div property="sioc:content">
                    <p>
                        Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
                    </p>
                    <p>
                        Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.
                    </p>
                </div>
           </article>

            <article typeof="http://rdfs.org/sioc/ns#Post" about="http://example.net/blog/second_news_item">
                <h1 property="dcterms:title">Another item</h1>
                <div property="sioc:content">
                    <p>Hello, world!</p>
                </div>
            </article>
        </div>
    </body>
</html>
